//JTempApplet.java -- Yet another Temperature example
//Lots motre comments are need here!!!!
package Applets;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;		

public class JTempApplet extends JApplet implements ActionListener 
{
    JPanel		panF, panC;
    JLabel		labF, labC;
    JTextField	textF, textC;
    JButton		convButton;

    public void init() 
    {
        Container container = getContentPane();
        container.setLayout(new BorderLayout());

        panF = new JPanel();
        panC = new JPanel();

        labF = new JLabel("Fahr:");
        panF.add(labF);		//add to panel F
        textF = new JTextField(15);
        panF.add(textF);
        container.add("North", panF);

        labC = new JLabel("Cent:");
        panC.add(labC);		//add to panel C
        textC = new JTextField(15);
        panC.add(textC);
        container.add("Center", panC);

        convButton = new JButton("Convert");
        container.add("South",convButton);


        // Register Component Listeners
        textF.addActionListener(this);
        textC.addActionListener(this);
        convButton.addActionListener(this);	
    }

    public void actionPerformed (ActionEvent e) 
    {
        DecimalFormat twoDigits = new DecimalFormat("0.00");
        if ((e.getSource() == textF)||(e.getSource() == convButton))
        {
            Double temp = new Double(textF.getText());
            double d = temp.doubleValue();
            d = 5*(d-32.0)/9;	//d = (d - 32.0)/1.8
            textC.setText(String.valueOf(twoDigits.format(d)));
        }
        else
        {
            Double temp = new Double(textC.getText());
            double d = temp.doubleValue();
            d = (9.0/5.0)*d + 32.0;	//d = 1.8*d + 32.0
            textF.setText(String.valueOf(twoDigits.format(d)));
        }
    }
}